<?php
//connect to the database
$connect = mysql_connect("localhost","root","root") or die("Check your server connection");

//create the ecommerce database
if(mysql_query("Create database wlf"))
{
echo "Woo hoo! Database created! <br>";
}
else
{
echo "sorry, try creating the database aagain.";
}
mysql_select_db("wlf");

//Define the product table
$query = "create table products (
		  products_prodnum char(5) NOT NULL,
		  products_name varchar(20) NOT NULL,
		  products_proddesc TEXT NOT NULL,
		  products_price DEC(6,2) NOT NULL,
		  products_dateadded DATE NOT NULL,
		  PRIMARY KEY(products_prodnum))";
		  
$product = mysql_query($query) or die(mysql_error());

//Define the customer table
$query2 = "create table customers (
		   customers_custnum INT(6) NOT NULL AUTO_INCREMENT,
		   customers_firstname varchar(15) NOT NULL,
		   customers_lastname varchar(50) NOT NULL,
		   customers_add1 varchar(50) NOT NULL,
		   customers_add2 varchar(50),
		   customers_city varchar(50) NOT NULL,
		   customers_state char(2) NOT NULL,
		   customers_zip char(5) NOT NULL,
		   customers_phone char(12) NOT NULL,
		   customers_fax char(12),
		   customers_email varchar(50) NOT NULL,
		   PRIMARY KEY(customers_custnum))";
		   
$customers = mysql_query($query2) or die(mysql_error());

//Define the general order table
$query3 = "create table ordermain (
		   ordermain_ordernum INT(6) NOT NULL AUTO_INCREMENT,
		   ordermain_orderdate DATE NOT NULL,
		   ordermain_custnum INT(6) NOT NULL,
		   ordermain_subtotal DEC(7,2) NOT NULL,
		   ordermain_shipping DEC(6,2),
		   ordermain_tax DEC(6,2),
		   ordermain_total DEC(7,2),
		   ordermain_shipfirst varchar(15) NOT NULL,
		   ordermain_shiplast varchar(50) NOT NULL,
		   ordermain_shipcompany varchar(50),
		   ordermain_shipadd1 varchar(50) NOT NULL,
		   ordermain_shipadd2 varchar(50),
		   ordermain_shipcity varchar(50) NOT NULL,
		   ordermain_shipstate char(10) NOT NULL,
		   ordermain_shipzip char(10) NOT NULL,
		   ordermain_shipphone char(12) NOT NULL,
		   ordermain_shipemail varchar(50),
		   PRIMARY KEY(ordermain_ordernum))";
		   
$ordermain = mysql_query($query3) or die(mysql_error());

//Define the order details table
$query4 = "create table orderdet (
		   orderdet_ordernum INT(6) NOT NULL,
		   orderdet_qty INT(3) NOT NULL,
		   orderdet_prodnum char(5) NOT NULL,
		   PRIMARY KEY(orderdet_ordernum))";
		   
$orderdet = mysql_query($query4) or die(mysql_error());

echo "Table create successfully";
?>
		   
		  


